import { platformOrderListColumns } from './platformOrderList.config.js'
import search from './../search/search.js';
import { shopInstockGoodsConfirm,shopInstockList } from '@/api/shop/stock/instock.js'
export default {
    name: "platformOrderList",
    mixins: [search],
    data() {
        return {
            platformOrderListColumns,
            loading: false,
            loadData: [],
            page: {
                current: 1,
                total: 0,
                size: 10
            },
            selectedRows: [],//选中的数组
            selectedRowKeys: [],  //选中的数组
            number: 0,
            btn: [
                {
                    title: "增加自建商品入库单",
                    isShow: true
                },
            ]
        }
    },
    methods: {
        getList(searchForm, page) {
            if (searchForm) {
                console.log('searchForm',searchForm)
            }
            if (page) {
                this.page.current = page
            }
            shopInstockList(Object.assign({deptId: this.$store.getters.userInfo.sysUser.deptId, tenantId: this.$store.getters.userInfo.sysUser.tenantId},searchForm, this.page)).then(val => {

                console.log("shopInstockList",val)
                let data = val.data
                this.page = {
                    current: data.current,
                    total: data.total,
                    size: data.size,
                }
                data.records.forEach(ele=>{
                    if(ele.inStockType== '00'){
                        ele.inStockTypeH = '门店采购门店入库单'
                    }
                    if(ele.inStockType== '04'){
                        ele.inStockTypeH = '门店自建入库单'
                    }
                    if(ele.inStockType== '06'){
                        ele.inStockTypeH = '平台主动出库门店入库单'
                    }

                    if(ele.status == '00'){
                        ele.statusH = '待入库'
                    }
                    if(ele.status == '01'){
                        ele.statusH = '部分入库'
                    }
                    if(ele.status == '02'){
                        ele.statusH = '已完成'
                    }
                    
                })

                this.loadData = data.records
                this.$emit("trigger")
            })
            // setTimeout(() => {
            //     this.page.total = 200
            //     this.$emit("trigger")
            // }, 500)

        },
        onShowSizeChange(current, size) {
            console.log(current, size)
            this.page.current = current
            this.page.size = size
            this.getList()
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectedRows = selectedRows;
            this.number = this.selectedRows.length
        },
        // 清空选中项
        clearSelection() {
            this.selectedRowKeys = []
            this.number = 0
        },
        handler(index) {
            if (index == 0) {
                this.platformOrderList()
            }
        },
        // 新增采购单
        platformOrderList() {
            this.$router.push({ path: "/shop/stock/instockList/addOrder" })
        },
        ruKuClick(item) {
            this.$router.push({ path: "/shop/stock/instockList/inOrder", query: { inStockId: item.inStockId,status:item.status} })
        },
        details(item) {
            this.$router.push({ path: "/shop/stock/instockList/inDetails", query: { inStockId: item.inStockId ,status:item.status} })
        },
        wanCheng(item) {
            var that = this
            this.$confirm({
                title: '确定要完成单据编号为' + item.inStockId + '的入库吗？',
                onOk() {
                    shopInstockGoodsConfirm({ inStockId: item.inStockId }).then(val => {
                        that.getList()
                        that.$message.success('入库成功')
                    })
                },
                class: 'test',
            });
        }
    }

} 